﻿Imports System.Data.SqlClient

Public Class frmPrintChartofAccount

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Me.Close()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Try
            Me.Cursor = Cursors.WaitCursor
            Dim dap As New SqlDataAdapter("Select Distinct N'" & Me.DTPPeriodFRm.Value.ToString & "' DestSource,N'" & _
                                          Me.DTPPeriodTo.Value.ToString & "' CustName,AccNo,Acc2," & _
                                          "dbo.GetAccBalance(AccNo,N'" & Me.DTPPeriodFRm.Value.ToShortDateString & " 00:00:00') TotalIn," & _
                                          "dbo.GetAccBalance(AccNo,N'" & Me.DTPPeriodTo.Value.ToShortDateString & " 23:59:59') TotalOut " & _
                                          "From Transactions", cnn)
            Dim das As New DataSet

            cnn.Open()
            dap.Fill(das, "Transactions")
            cnn.Close()

            Dim rpt As New ChartOfAccountsBalances
            rpt.SetDataSource(das)
            rptViewer.CrystalReportViewer1.ReportSource = rpt
            rptViewer.CrystalReportViewer1.RefreshReport()
            rptViewer.ShowDialog()

            Me.Cursor = Cursors.Default
        Catch ex As Exception
            Me.Cursor = Cursors.Default
            If cnn.State = ConnectionState.Open Then
                cnn.Close()
            End If
            MsgBox(ex.ToString)
        End Try
    End Sub
End Class